package com.xju.admin.service.Impl;

import com.xju.admin.entity.Section;
import com.xju.admin.entity.SectionExample;
import com.xju.admin.mapper.SectionMapper;
import com.xju.admin.service.SectionService;
import com.xju.admin.utils.IDGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SectionServiceImpl implements SectionService {

    @Autowired
    private SectionMapper sectionMapper;

    @Override
    public List<Section> findAll() {
        SectionExample sectionExample=new SectionExample();
        sectionExample.createCriteria().andSecIdIsNotNull();
        List<Section> sectionList=sectionMapper.selectByExampleWithBLOBs(sectionExample);
        return sectionList;
    }

    @Override
    public Section findById(String id) {
        SectionExample sectionExample=new SectionExample();
        sectionExample.createCriteria().andSecIdEqualTo(id);
        Section section=sectionMapper.selectByExampleWithBLOBs(sectionExample).get(0);
        return section;
    }

    @Override
    public void modify(Section section) {
        sectionMapper.updateByPrimaryKeyWithBLOBs(section);
    }

    @Override
    public void add(String name, String describe) {
        Section section=new Section();
        section.setSecId(IDGenerator.getId());
        section.setSecName(name);
        section.setSecDescribe(describe);
        sectionMapper.insert(section);
    }

    @Override
    public void delete(String id) {
        sectionMapper.deleteByPrimaryKey(id);
    }
}

